


window.onload = ()=>{
    console.log("123")

    const classTime = [
        ["08:30","09:10"],
        ["09:20","10:00"],
        ["10:10","10:50"],
        ["11:00","11:40"],
        ["11:40","12:20"],
        ["15:00","15:40"],
        ["15:50","16:30"],
        ["16:40","17:20"],
        ["19:30","20:10"],
        ["20:10","20:50"],
        ["20:50","21:30"],
    ]
    // const data = {
    //     'now_week': '7',
    //     "day":"星期一",
    //     "date":"1697994375.1129553",
    //     'last_update_time': '1697994375.1129553',
    //     'data':
    //         [
    //             {'class_name': 'Python程序设计', 'teacher_name': '叶李霞', 'start': '1', 'end': '3', 'class_room': '3号楼J504'},
    //             {'class_name': '中国近现代史纲要', 'teacher_name': '田雪', 'start': '4', 'end': '5', 'class_room': '4号楼501（中）'},
    //             {'class_name': '数据结构', 'teacher_name': '邢中玉', 'start': '9', 'end': '11', 'class_room': '4号楼404（阶梯）'}
    //         ]
    // }


    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const dataStr = urlParams.get("data")
    console.log(dataStr)
    const data = JSON.parse(dataStr)

    const classTable = document.getElementById("classTable")
    let classTableStr = ''

    for (const line of data.data){
        classTableStr += `
        <div class="class-object">
                    <div>
                        <div>${line.start}-${line.end}节</div>
                        <div>${classTime[parseInt(line.start)-1][0]}-${classTime[parseInt(line.end)-1][1]}</div>
                    </div>
                    <div>
                        <div>${line.class_name}</div>
                        <div>（${line.class_room}）</div>
                    </div>
                </div>
    `
    }
    classTable.innerHTML = classTableStr

    // 1697994375112
    const updateDate = new Date(Number(data.last_update_time.replace(/[^\d]/g,'').slice(0,13)));
    const date = new Date(Number(data.date.replace(/[^\d]/g,'').slice(0,13)));

    console.log(parseInt(data.last_update_time).toString())
    document.getElementById("weekDay").innerHTML = `${data.day}`;
    document.getElementById("week").innerHTML = `第${data.now_week}周`;
    document.getElementById("showDate").innerHTML =
        `${date.getFullYear()}年${date.getMonth()+1}月${date.getDate()}日`;
    document.getElementById("dataUpdate").innerHTML =

        `Database ${updateDate.getFullYear()}年${updateDate.getMonth()+1}月${updateDate.getDate()}日 ${updateDate.getHours()}:${updateDate.getMinutes()}:${updateDate.getSeconds()}`

    html2canvas(document.querySelector("#mainBox"), {
        backgroundColor: null, //画出来的图片有白色的边框,不要可设置背景为透明色（null）
        useCORS: true, //支持图片跨域
        scale: 1, //设置放大的倍数
    }).then(canvas => {
        console.log(canvas)
        // document.getElementById("showImage").appendChild(canvas).toDataURL()
        document.getElementById("showImage").innerHTML = `
        <img src="${canvas.toDataURL()}" />
        `
    });
}